package com.google.fbyoutube.shared;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class ytVideoEntry implements Serializable, Cloneable{
	
	@PrimaryKey
	private String id = null;
	
	@Persistent
	private String shortId = null;
	
	@Persistent
	private String title = null;
	
	@Persistent
	private String author = null;
	
	@Persistent
	private long views = 0;
	
	@Persistent
	private float rateAverage = 0;
	
	@Persistent
	private int rateCount = 0;
	
	@Persistent
	private long favCount = 0;
	
	@Persistent
	private String summaryPlainText = null;
	
	@Persistent
	private String mediaGroupPlayerUrl = null;
	
	@Persistent
	private String mediaGroupRuntime = null;
	
	@Persistent
	private String mediaGroupDescription = null;
	
	@Persistent
	private List<String> mediaGroupThumbnails = null;
	
	@Persistent
	private List<String> mediaGroupKeyWords = null;
	
	@Persistent
	private List<String> mediaGroupContentUrls = null;
	
	@Persistent
	private List<String> mediaGroupContentTypes = null;
	
	@Persistent
	private List<String> mediaGroupContentDurations = null;

	public String getTitle() {
		if (title == null)
			title = "";
		return title;
	}
	
	public String getShortTitle() {
		String shortTitle = title;
		if (title == null)
			shortTitle = "";
		if (title.length() > 15) {
			shortTitle = title.substring(0, 15);
			shortTitle += "...";
		}
		return shortTitle;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getSummaryPlainText() {
		if (summaryPlainText == null)
			summaryPlainText = "";
		return summaryPlainText;
	}

	public void setSummaryPlainText(String summaryPlainText) {
		this.summaryPlainText = summaryPlainText;
	}

	public String getMediaGroupPlayerUrl() {
		if (mediaGroupPlayerUrl == null)
			mediaGroupPlayerUrl = "";
		return mediaGroupPlayerUrl;
	}

	public void setMediaGroupPlayerUrl(String mediaGroupPlayerUrl) {
		this.mediaGroupPlayerUrl = mediaGroupPlayerUrl;
	}

	public List<String> getMediaGroupThmbnails() {
		if (mediaGroupThumbnails == null)
			mediaGroupThumbnails = new ArrayList<String>();
		return mediaGroupThumbnails;
	}

	public List<String> getMediaGroupKeyWords() {
		if (mediaGroupKeyWords == null)
			mediaGroupKeyWords = new ArrayList<String>();
		return mediaGroupKeyWords;
	}

	public List<String> getMediaGroupContentUrls() {
		if (mediaGroupContentUrls == null) 
			mediaGroupContentUrls = new ArrayList<String>();
		return mediaGroupContentUrls;
	}

	public List<String> getMediaGroupContentTypes() {
		if (mediaGroupContentTypes == null) 
			mediaGroupContentTypes = new ArrayList<String>();
		return mediaGroupContentTypes;
	}

	public List<String> getMediaGroupContentDurations() {
		if (mediaGroupContentDurations == null) 
			mediaGroupContentDurations = new ArrayList<String>();
		return mediaGroupContentDurations;
	}

	public String getAuthor() {
		if (author == null)
			author = "";
		return author;
	}
	
	public String getShortAuthor() {
	  if (author == null) 
	    author = "";
	  if (author.length() > 15) {
	    author = author.substring(0, 15) + "...";
	  }
	  return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public long getViews() {
		return views;
	}

	public void setViews(long views) {
		this.views = views;
	}

	public String getId() {
		return id;
//		return getShortId();
	}

	public void setId(String id) {
		this.id = id;
		if (this.id.indexOf(":") != -1) {
			this.id = this.id.substring(this.id.lastIndexOf(":") + 1);
		}
	}

	public float getRateAverage() {
		return rateAverage;
	}

	public void setRateAverage(float rateAverage) {
		this.rateAverage = rateAverage;
	}

	public int getRateCount() {
		return rateCount;
	}

	public void setRateCount(int rateCount) {
		this.rateCount = rateCount;
	}

	public long getFavCount() {
		return favCount;
	}

	public void setFavCount(long favCount) {
		this.favCount = favCount;
	}

	public String getShortId() {
		return shortId;
	}

	public void setShortId(String shortId) {
		this.shortId = shortId;
	}

	public String getMediaGroupDescription() {
		return mediaGroupDescription;
	}
	
	public String getMediaGroupDescriptionShort(int size) {
		if (size < 10) size = 10;
		if (mediaGroupDescription == null || mediaGroupDescription.length() < size) {
			return mediaGroupDescription;
		}
		if (mediaGroupDescription != null) {
			return mediaGroupDescription.substring(0, size);
		}
		return null;
	}

	public void setMediaGroupDescription(String mediaGroupDescription) {
		if (mediaGroupDescription.length() > 400)
			this.mediaGroupDescription = mediaGroupDescription.substring(0, 400);
		else
			this.mediaGroupDescription = mediaGroupDescription;
	}

	public String getMediaGroupRuntime() {
		return mediaGroupRuntime;
	}

	public void setMediaGroupRuntime(String mediaGroupRuntime) {
		this.mediaGroupRuntime = mediaGroupRuntime;
	}
}
